package com.yoda.mall.admin.controller;

import com.yoda.mall.admin.service.FlashProductRelationService;
import com.yoda.mall.model.dto.CouponDto;
import com.yoda.mall.model.entity.sms.Coupon;
import com.yoda.mall.model.entity.sms.FlashPromotionProductRelation;
import com.yoda.mall.model.vo.CouponVo;
import com.yoda.mall.model.vo.FlashPromotionProductRelationVo;
import com.yoda.mall.model.vo.PageResult;
import com.yoda.mall.model.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("flashProductRelation")
public class FlashProductRelationController {
    @Autowired
    private FlashProductRelationService flashProductRelationService;

    //批量选择商品添加关联
    @PostMapping("create")
    public R createFlashProductRelation(@RequestBody List<FlashPromotionProductRelation> flashPromotionProductRelations){
        flashProductRelationService.createFlashProductRelation(flashPromotionProductRelations);
        return R.success();
    }

    //删除关联
    @PostMapping("delete/{id}")
    public R deleteFlashProductRelation(@PathVariable Long id){
        flashProductRelationService.deleteFlashProductRelation(id);
        return R.success();
    }

    //分页查询不同场次关联及商品信息
    @GetMapping("list")
    public R flashProductRelationList(Long flashPromotionId,Long flashPromotionSessionId,Integer pageNum,Integer pageSize){
        PageResult<FlashPromotionProductRelationVo> pageResult = flashProductRelationService.flashProductRelationListPage(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);
        return R.success(pageResult);
    }

    //修改关联信息
    @PostMapping("update/{id}")
    public R updateFlashPromotionProductRelation(@RequestBody FlashPromotionProductRelation flashPromotionProductRelation,@PathVariable Long id){
        flashProductRelationService.updateFlashPromotionProductRelation(flashPromotionProductRelation,id);
        return R.success();
    }

    //获取管理商品促销信息
    @GetMapping("{id}")
    public R getFlashPromotionProductRelation(@PathVariable Long id){
        FlashPromotionProductRelation flashPromotionProductRelation = flashProductRelationService.getFlashPromotionProductRelation(id);
        return R.success(flashPromotionProductRelation);
    }
}
